package org.codingq92.basic.thread;

import org.openjdk.jol.info.ClassLayout;

/**
 * Synchronized锁升级<br/>
 * 无锁状态 → 偏向锁（单线程访问） → 轻量级锁（多线程交替访问） → 重量级锁（多线程同时竞争）
 *
 * @author: CodingQ92
 * @date: 2025/6/4 21:28
 */
public class SynchronizedLock {
    public static void main(String[] args) throws InterruptedException {
        class T {
            int age;
        }
        Thread.sleep(4100);

        // 无锁状态
        T t = new T();
//        System.out.println(ClassLayout.parseInstance(t).toPrintable());

        // 偏向锁
        synchronized (t) {
            System.out.println(ClassLayout.parseInstance(t).toPrintable());
        }
        System.out.println("--------------------------------------------");
        synchronized (t) {
            System.out.println(ClassLayout.parseInstance(t).toPrintable());
        }
    }
}
